clear 

* set directory 
* cd "directory"

* set paths
global datafolder "data"
global outputfolder "output"

********************************************************************************
*	Table 4: Pass-through coefficients before and after the third memorandum
********************************************************************************

	use "$datafolder\maindata.dta", clear

	keep if datem >= 660
	
	sort customerid datem
	bysort customerid: gen be_first_x = theoretical_rate if _n==1 & year==2015
	bysort customerid: egen be_first = max(be_first_x)
	
	gen datem_crisis = .
	replace datem_crisis=0 if inrange(datem,664,665)
	replace datem_crisis=1 if inrange(datem,666,671)
				
	label define datem_crisis_lb 0 "2015m5-m6" 1 "D\$_{post}$"
	label values datem_crisis datem_crisis_lb  
	
	label variable theoretical_rate "Breakeven Rate"
	
	estimates clear
	
	reghdfe actual_rate c.theoretical_rate i.datem_crisis  ///
		ib0.datem_crisis#c.theoretical_rate if inrange(datem,664,671), ///
		abs(datem) cluster(customerid)
	quietly estadd local hasdt "Yes"
	quietly estadd local hasind "No"
	quietly estadd local hasf "No"
	estimates store M1	
	
	reghdfe actual_rate c.theoretical_rate i.datem_crisis  ///
		ib0.datem_crisis#c.theoretical_rate if inrange(datem,664,671), ///
		abs(datem Industry) cluster(customerid)
	quietly estadd local hasdt "Yes"
	quietly estadd local hasind "Yes"
	quietly estadd local hasf "No"
	estimates store M2	
	
	reghdfe actual_rate c.theoretical_rate i.datem_crisis  ///
		ib0.datem_crisis#c.theoretical_rate if inrange(datem,664,671), ///
		abs(datem firmid Industry) cluster(customerid)
	quietly estadd local hasdt "Yes"
	quietly estadd local hasind "Yes"
	quietly estadd local hasf "Yes"
	estimates store M3	
	
	esttab * using "$outputfolder\table_4.tex", replace b(3) se(3) r(3) ///
	drop(_cons 0.datem_crisis 1.datem_crisis 0.datem_crisis#c.theoretical_rate) ///
	se r2 label star(* 0.1 ** 0.05 *** 0.01) nonotes substitute(\_ _) ///
	scalars("hasdt Month FE" "hasind Industry FE" "hasf Firm FE")
	